package org.xx.armory.config;

import org.xx.armory.commons.AbstractLifeCycle;
import org.xx.armory.commons.LifeCycle;

import java.util.Objects;

import static org.xx.armory.commons.Validators.notBlank;

public final class MockDecorator
        extends AbstractLifeCycle
        implements LifeCycle {
    private String target;
    private String action;

    public MockDecorator() {
        this.target = "";
        this.action = "";
    }

    public MockDecorator(
            String target,
            String action
    ) {
        setTarget(target);
        setAction(action);
    }

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = notBlank(target, "target").trim();
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = notBlank(action, "action").trim();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return this.getAction().hashCode() * 31 + this.getTarget().hashCode();
    }

    /**
     * {@inheritDoc}
     * <p>检查所有字段来判断是否相等。</p>
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != this.getClass()) {
            return false;
        }

        final MockDecorator other = (MockDecorator) obj;
        return Objects.equals(getAction(), other.getAction()) &&
                Objects.equals(getTarget(), other.getTarget());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "MockDecorator{target=" + getTarget() + ",action=" + getAction() + "}";
    }
}
